package com.project.controller;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@RestController
@RequestMapping("online")
public class onlineController {
    @RequestMapping("getNum")
    public String getNum(HttpServletRequest request){
        HttpSession session = request.getSession();

        //从上下文得到在线人数
        int num = (Integer)session.getServletContext().getAttribute("online");
        return "在线人数:"+num;
    }

    @RequestMapping("destroy")
    public String destroySession(HttpServletRequest request){
        HttpSession session = request.getSession();
        //强行销毁session
        session.invalidate();
        int num = (Integer) request.getServletContext().getAttribute("online");
        return "在线人数:"+num;
    }

}
